//graham matuszewski
#pragma once

#ifndef FEEDERTEST_H_
#define FEEDERTEST_H_

#include <iostream>
#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include "Agent.h"
#include "GantryAgentMock.h"
#include "GUIFeederMock.h"
#include "FeederAgent.h"
#include "Feeder.h"
#include "LaneAgentMock.h"
#include <string>
//test of the feeder
std::string tempTest="Feeder Test";
class FeederTest : public ::testing::Test {
public:
	FeederTest() : feeder(tempTest){


	}
	//virtual ~TestKittingCell(){delete &feeder;}
	FeederAgent feeder;
	//LaneAgentMock bottomLaneMock;
//	LaneAgentMock topLaneMock;
	GantryAgentMock gantryMock;
	//GUIFeederMock guiFeederMock;

//	int PullInMyLibrary() { return 0; }
	virtual void SetUp() {
		feeder.setGantry(&gantryMock);
	}

	bool isGuiStarted() {

		//feeder =FeederAgent(name);
		return feeder.guiStatus();
	}
	bool isFeederMoving(){
		return feeder.movingStatus();
	}
	bool isPurgeHappening(){
		return feeder.purgeStatus();
	}

	bool runScheduler(){
		return feeder.pickAndExecuteAnAction();
	}
	Gantry* getGantryFromFeeder(){
		return feeder.getGantryAgent();
	}
	/*
	LaneAgent* getBottomFromFeeder(){
		return feeder->getBottomAgent();
	}
	LaneAgent* getTopFromFeeder(){
		return feeder->getTopAgent();
	}
	*/
	
};
//init test

TEST_F(FeederTest, InitialTest){
	try{
	EXPECT_FALSE(isGuiStarted());
	
	EXPECT_FALSE(isFeederMoving());
	EXPECT_FALSE(isPurgeHappening());
	//EXPECT_TRUE(true);
	//std::cout<<"IS THIS SHIT WORKING";
	//std::getchar();
	}
	catch(std::exception &e){
		std::cout<<"wtf is this shit";
	}

}



//set lanes and gantry
TEST_F(FeederTest, setLanes){

	//feeder.setGantry(gantryMock);
	//feeder->setLaneBottom(&bottomLaneMock);
	//feeder->setLaneTop(&topLaneMock);

//	EXPECT_EQ(getGantryFromFeeder(),&gantryMock);
	//EXPECT_EQ(getBottomFromFeeder(),bottomLaneMock);
	//EXPECT_EQ(getTopFromFeeder(),topLaneMock);

}




/*
//feeder will receive its first message and send one to the gantry
TEST_F(TestKittingCell, recieveMessageAndSend){
	PartType part1;
	part1
	feeder.msgPleaseGetParts(


}
TEST_F(ConveyorAgentTest, SensorEmptyFullMessage){
	GuiSensorMock *beg = new GuiSensorMock();
	GuiSensorMock *end = new GuiSensorMock();
	GuiSensorMock *bef = new GuiSensorMock();

	GuiPopupMock *pop = new GuiPopupMock();

	agent.setGUISensors(beg, end, bef);
	agent.setGUIPopup(pop);

	//expect empty to begin with
	EXPECT_EQ(getBegSensorStat(),0);//expect sensor empty to begin... 0 = EMPTY
	EXPECT_EQ(getEndSensorStat(),0);//expect sensor empty to begin... 0 = EMPTY
	EXPECT_EQ(getBefSensorStat(),0);//expect sensor empty to begin... 0 = EMPTY

	//set full
	agent.msgImFull(beg);
	EXPECT_EQ(getBegSensorStat(),1);//expect beg sensor to be full
	EXPECT_EQ(getEndSensorStat(),0);//expect end to remain empty
	EXPECT_EQ(getBefSensorStat(),0);//expect bef to remain empty

	agent.msgImFull(end);
	EXPECT_EQ(getBegSensorStat(),1);//expect beg to remain full
	EXPECT_EQ(getEndSensorStat(),1);//expect end to be full
	EXPECT_EQ(getBefSensorStat(),0);//expect bef to remain empty

	agent.msgImFull(bef);
	EXPECT_EQ(getBegSensorStat(),1);//expect beg to remain full
	EXPECT_EQ(getEndSensorStat(),1);//expect end to remain full
	EXPECT_EQ(getBefSensorStat(),1);//expect bef to full

	//set empty now
	agent.msgImEmpty(bef);
	EXPECT_EQ(getBegSensorStat(),1);//expect beg to remain full
	EXPECT_EQ(getEndSensorStat(),1);//expect end to remain full
	EXPECT_EQ(getBefSensorStat(),0);//expect bef to empty

	agent.msgImEmpty(end);
	EXPECT_EQ(getBegSensorStat(),1);//expect beg to remain full
	EXPECT_EQ(getEndSensorStat(),0);//expect end to be empty
	EXPECT_EQ(getBefSensorStat(),0);//expect bef to remain empty

	agent.msgImEmpty(beg);
	EXPECT_EQ(getBegSensorStat(),0);//expect beg to be empty
	EXPECT_EQ(getEndSensorStat(),0);//expect end to remain empty
	EXPECT_EQ(getBefSensorStat(),0);//expect bef to remain empty

}
//turn on normally
TEST_F(ConveyorAgentTest, TurnOnNormal){
	GuiSensorMock *beg = new GuiSensorMock();
	GuiSensorMock *end = new GuiSensorMock();
	agent.setGUISensors(beg, end);

	EXPECT_CALL(guiConveyor,startConveyor());//expect the start
	EXPECT_EQ(runScheduler(),true);	//will start conveyor
	EXPECT_EQ(runScheduler(),false); //nothing else to do
}


TEST_F(ConveyorAgentTest, SchedulerReturnTestWOGlassInQ){
	EXPECT_EQ(runScheduler(),false); //not on
}

TEST_F(ConveyorAgentTest, SchedulerReturnTestWOGlassInQWImFreeCall){
	//agent.msgImFree(&nextAgent);
	//EXPECT_EQ(runScheduler(),true);
}

TEST_F(ConveyorAgentTest, SchedulerReturnTestWithGlassInQNormal){
	/*Glass glass(1);
	agent.msgHereIsGlass(&glass);
	EXPECT_CALL(nextAgent,msgHereIsGlass(&glass));
	EXPECT_CALL(prevAgent,msgImFree(&agent));
	EXPECT_EQ(runScheduler(),true);
	//agent.msgImFree(&nextAgent);
	//EXPECT_EQ(runScheduler(),true);*/
	// 
	// 
/*
}

// Got one glass
TEST_F(ConveyorAgentTest, GotOneGlass) {
	GuiSensorMock *beg = new GuiSensorMock();
	GuiSensorMock *end = new GuiSensorMock();
	agent.setGUISensors(beg, end);

	agent.msgHereIsGlass(&Glass(1));
	EXPECT_EQ(myGlassesSize(), 1);
}

// Before popup sensor full. Popup is up. Expect stop Conveyor.
TEST_F(ConveyorAgentTest, GlassApproachingPopup) {
	GuiPopupMock *popup = new GuiPopupMock();
	GuiSensorMock *beg = new GuiSensorMock();
	GuiSensorMock *end = new GuiSensorMock();
	GuiSensorMock *bef = new GuiSensorMock();
	agent.setGUIPopup(popup);
	agent.setGUISensors(beg, end, bef);

	EXPECT_EQ(runScheduler(),true);//start conveyor

	agent.msgPopupUp();//popup up
	agent.msgImFull(end);//popup up so endsensor full
	agent.msgImFull(bef);//before popup full

	Glass glass(1);
	agent.msgHereIsGlass(&glass);

	EXPECT_CALL(guiConveyor,stopConveyor());
	EXPECT_EQ(runScheduler(),true);	//stop conveyor
	EXPECT_EQ(runScheduler(),false); //nothing else to do

}

// End sensor full. There is no popup. Next is free. Expect pass. Glass needs next
TEST_F(ConveyorAgentTest, GlassNeedsNextNoPopup) {
	GuiSensorMock *beg = new GuiSensorMock();
	GuiSensorMock *end = new GuiSensorMock();
	agent.setGUISensors(beg,end);
	agent.setNextType(0);//type RAW

	EXPECT_EQ(runScheduler(),true);//starts conveyor

	agent.msgImFull(end);
	Glass glass(0);//type A(needs RAW)
	agent.msgHereIsGlass(&glass);
	
	EXPECT_CALL(nextAgent,msgHereIsGlass(&glass));
	EXPECT_EQ(runScheduler(),true);//send glass

}
TEST_F(ConveyorAgentTest, GlassDoesNotNeedsNextNoPopup) {
	/*GuiSensorMock *beg = new GuiSensorMock();
	GuiSensorMock *end = new GuiSensorMock();
	agent.setGUISensors(beg,end);
	agent.setNextType(4);//type DRILLED

	EXPECT_EQ(runScheduler(),true);//starts conveyor

	agent.msgImFull(end);
	Glass glass(2);//type C(does not need drilled)
	agent.msgHereIsGlass(&glass);
	

	EXPECT_CALL(bypassAgent,msgHereIsGlass(&glass));
	EXPECT_EQ(runScheduler(),true);//send glass
	EXPECT_CALL(guiConveyor,stopConveyor());
	EXPECT_EQ(runScheduler(),true);//turn off
	EXPECT_EQ(runScheduler(),false);//nothing else to do*/
	//BYPASSES NOT YET IMPLEMENTEd

/*
}
// End sensor full. There is no popup. Next is not free. Glass needs next. Expect Stop
TEST_F(ConveyorAgentTest, GlassNeedsNextNoPopupNextNotFree) {
	GuiSensorMock *beg = new GuiSensorMock();
	GuiSensorMock *end = new GuiSensorMock();
	agent.setGUISensors(beg,end);
	agent.setNextType(0);//type RAW

	EXPECT_EQ(runScheduler(),true);//starts conveyor

	agent.msgImFull(end);

	Glass glass(0);//type A(needs RAW)
	Glass glass2(0);//another glass of type a
	EXPECT_EQ(myGlassesSize(),0);
	agent.msgHereIsGlass(&glass);//send first glass
	EXPECT_EQ(myGlassesSize(),1);

	EXPECT_CALL(nextAgent,msgHereIsGlass(&glass));//expect send first glass to next 
	EXPECT_CALL(guiConveyor,dropOff());//dropoff called
	EXPECT_EQ(runScheduler(),true);//send glass - Nextstatus is now not free
	EXPECT_EQ(getNextStat(),1); // next not frees
	
	EXPECT_EQ(myGlassesSize(),0);
	agent.msgHereIsGlass(&glass2);//send second glass
	EXPECT_EQ(myGlassesSize(),1);

	EXPECT_CALL(guiConveyor,stopConveyor());//expect stop because next not free

	EXPECT_EQ(runScheduler(),true);//turn off
	EXPECT_EQ(runScheduler(),false);//nothing else to do

	EXPECT_EQ(myGlassesSize(),1);
	
	

}
//Continuation of above, next becomes free and conveyor starts up
TEST_F(ConveyorAgentTest, GlassNeedsNextNoPopupConveyorOffNextNowFree){
	GuiSensorMock *beg = new GuiSensorMock();
	GuiSensorMock *end = new GuiSensorMock();
	agent.setGUISensors(beg,end);
	agent.setNextType(0);//type RAW

	Glass glass(0);//type A(needs RAW)


	agent.msgImFull(end);
	agent.setNextStatusNotFree();
	agent.msgHereIsGlass(&glass);//send second glass
	
	EXPECT_EQ(runScheduler(),false);//nothing to do
	
	//Above creates the situation
	//conveyor should now start

	agent.msgImFree(&nextAgent);//next agent now free
	EXPECT_EQ(getNextStat(),0); // next now free
	EXPECT_CALL(guiConveyor,startConveyor());//expect start because next now free
	EXPECT_EQ(runScheduler(),true);//starts conveyor

	EXPECT_CALL(nextAgent,msgHereIsGlass(&glass));//expect send  glass to next 
	EXPECT_CALL(guiConveyor,dropOff());//dropoff called
	EXPECT_EQ(runScheduler(),true);//send glass - Nextstatus is now not free
	EXPECT_EQ(getNextStat(),1); // next not frees

	EXPECT_CALL(guiConveyor,stopConveyor());//expect stop because next not free
	EXPECT_EQ(runScheduler(),true);//turn off
	EXPECT_EQ(runScheduler(),false);//nothing else to do
}
//Above tests are andy approved

// End sensor is full. Glass needs popup. Expect popup.
TEST_F(ConveyorAgentTest, GlassOnPopupSensorNeedsPopup) {
	GuiPopupMock *popup = new GuiPopupMock();
	GuiSensorMock *beg = new GuiSensorMock();
	GuiSensorMock *end = new GuiSensorMock();
	GuiSensorMock *bef = new GuiSensorMock();
	agent.setGUIPopup(popup);
	agent.setGUISensors(beg, end, bef);
	EXPECT_EQ(getHasPopup(),true);
	Glass glass(1);
	agent.msgHereIsGlass(&glass);
	agent.msgImFull( end );
	EXPECT_CALL(*popup,goUp());
}

// End sensor is not full. Conveyor is off. Does not have popup. Glass list not empty. Expect start Conveyor.
TEST_F(ConveyorAgentTest, ConveyorOffEndSensorNotFullDoesNotHavePopupGlassOnConveyor) {
	GuiSensorMock *beg = new GuiSensorMock();
	GuiSensorMock *end = new GuiSensorMock();
	agent.setGUISensors(beg, end);

	EXPECT_EQ(getHasPopup(),false); //does not have popup
	EXPECT_EQ(getMyStat(),1); // need this to be OFF

//	agent.msgImEmpty(end);	//end sensor not full by default
	//EXPECT_EQ(runScheduler(),true);
	Glass glass(1);
	agent.msgHereIsGlass(&glass);
	EXPECT_CALL(guiConveyor,startConveyor());
	EXPECT_EQ(runScheduler(),true);
	
}

// End sensor is not full. Conveyor is off. Has popup. Before popup sensor is full and popup is down. Glass list not empty. Expect start Conveyor.
TEST_F(ConveyorAgentTest, ConveyorOffEndSensorNotFullHasPopupPopupIsDownGlassOnConveyor) {

}

// End sensor is not full. Conveyor is off. Has popup. Before popup sensor is not full. Expect start Conveyor.
TEST_F(ConveyorAgentTest, ConveyorOffEndSensorNotFullHasPopupBeforePopupSensorNotFull) {
	GuiPopupMock *popup = new GuiPopupMock();
	GuiSensorMock *beg = new GuiSensorMock();
	GuiSensorMock *end = new GuiSensorMock();
	GuiSensorMock *bef = new GuiSensorMock();
	agent.setGUIPopup(popup);
	agent.setGUISensors(beg, end, bef);

	EXPECT_EQ(getHasPopup(),true);
	Glass glass(1);
	agent.msgHereIsGlass(&glass);
	agent.msgImEmpty( end );
	agent.msgImEmpty( bef );
	EXPECT_CALL(guiConveyor,startConveyor());
	EXPECT_EQ(runScheduler(),true);
	
}
*/
#endif